﻿using System;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Party.PartyComponents
{
	// Token: 0x020002B2 RID: 690
	public class MilitiaPartyComponent : PartyComponent
	{
		// Token: 0x06002818 RID: 10264 RVA: 0x000AB47B File Offset: 0x000A967B
		internal static void AutoGeneratedStaticCollectObjectsMilitiaPartyComponent(object o, List<object> collectedObjects)
		{
			((MilitiaPartyComponent)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x06002819 RID: 10265 RVA: 0x000AB489 File Offset: 0x000A9689
		protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
		{
			base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			collectedObjects.Add(this.Settlement);
		}

		// Token: 0x0600281A RID: 10266 RVA: 0x000AB49E File Offset: 0x000A969E
		internal static object AutoGeneratedGetMemberValueSettlement(object o)
		{
			return ((MilitiaPartyComponent)o).Settlement;
		}

		// Token: 0x17000A16 RID: 2582
		// (get) Token: 0x0600281B RID: 10267 RVA: 0x000AB4AB File Offset: 0x000A96AB
		// (set) Token: 0x0600281C RID: 10268 RVA: 0x000AB4B3 File Offset: 0x000A96B3
		[SaveableProperty(1)]
		public Settlement Settlement { get; private set; }

		// Token: 0x17000A17 RID: 2583
		// (get) Token: 0x0600281D RID: 10269 RVA: 0x000AB4BC File Offset: 0x000A96BC
		public override Hero PartyOwner
		{
			get
			{
				return this.Settlement.OwnerClan.Leader;
			}
		}

		// Token: 0x17000A18 RID: 2584
		// (get) Token: 0x0600281E RID: 10270 RVA: 0x000AB4CE File Offset: 0x000A96CE
		public override TextObject Name
		{
			get
			{
				if (this._cachedName == null)
				{
					this._cachedName = GameTexts.FindText("str_militia_name", null);
					this._cachedName.SetTextVariable("SETTLEMENT_NAME", this.Settlement.Name);
				}
				return this._cachedName;
			}
		}

		// Token: 0x17000A19 RID: 2585
		// (get) Token: 0x0600281F RID: 10271 RVA: 0x000AB50B File Offset: 0x000A970B
		public override Settlement HomeSettlement
		{
			get
			{
				return this.Settlement;
			}
		}

		// Token: 0x06002820 RID: 10272 RVA: 0x000AB514 File Offset: 0x000A9714
		public static MobileParty CreateMilitiaParty(string stringId, Settlement settlement)
		{
			MobileParty mobileParty2 = MobileParty.CreateParty("militias_of_" + stringId + "_aaa1", new MilitiaPartyComponent(settlement), delegate(MobileParty mobileParty)
			{
				(mobileParty.PartyComponent as MilitiaPartyComponent).InitializeMilitiaPartyProperties(mobileParty, settlement);
			});
			EnterSettlementAction.ApplyForParty(mobileParty2, settlement);
			return mobileParty2;
		}

		// Token: 0x06002821 RID: 10273 RVA: 0x000AB566 File Offset: 0x000A9766
		protected override void OnInitialize()
		{
			this.Settlement.MilitiaPartyComponent = this;
		}

		// Token: 0x06002822 RID: 10274 RVA: 0x000AB574 File Offset: 0x000A9774
		protected override void OnFinalize()
		{
			this.Settlement.MilitiaPartyComponent = null;
		}

		// Token: 0x06002823 RID: 10275 RVA: 0x000AB582 File Offset: 0x000A9782
		public override void ClearCachedName()
		{
			this._cachedName = null;
		}

		// Token: 0x06002824 RID: 10276 RVA: 0x000AB58C File Offset: 0x000A978C
		private void InitializeMilitiaPartyProperties(MobileParty mobileParty, Settlement settlement)
		{
			PartyTemplateObject militiaPartyTemplate = settlement.Culture.MilitiaPartyTemplate;
			mobileParty.InitializeMobilePartyAtPosition(militiaPartyTemplate, settlement.GatePosition, -1);
			mobileParty.Party.SetVisualAsDirty();
			mobileParty.Ai.DisableAi();
			mobileParty.Aggressiveness = 0f;
		}

		// Token: 0x06002825 RID: 10277 RVA: 0x000AB5D4 File Offset: 0x000A97D4
		protected internal MilitiaPartyComponent(Settlement settlement)
		{
			this.Settlement = settlement;
		}

		// Token: 0x04000C36 RID: 3126
		[CachedData]
		private TextObject _cachedName;
	}
}
